package com.shiguiwu.springmybatis.javabase.nio.socket;

import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.DatagramChannel;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.TimeUnit;

/**
 * @description: DatagramChannel
 * @author: stone
 * @date: Created by 2021/11/8 15:48
 * @version: 1.0.0
 * @pakeage: com.shiguiwu.springmybatis.nio.socket
 */
public class DatagramTests {

    public static void main(String[] args) throws Exception {
        //开启一个
        DatagramChannel sendDatagramChannel = DatagramChannel.open();

        //创建一个 InetSocketAddress
        InetSocketAddress inetSocketAddress = new InetSocketAddress("127.0.0.1", 9999);

        while (true) {
            ByteBuffer byteBuffer = ByteBuffer.wrap("发送数据".getBytes(StandardCharsets.UTF_8));
            sendDatagramChannel.send(byteBuffer, inetSocketAddress);
            System.out.println("数据发送完毕");
            TimeUnit.SECONDS.sleep(5);
        }





    }
}
